package com.example.gitpart03;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;

public class Login extends AppCompatActivity {
    private CheckBox checkBox;
    private Button wechatLoginButton;
    private EditText accountEditText;
    private EditText codeEditText;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.yogurt_login_choose);
        checkBox = findViewById(R.id.checkbox_id);
        wechatLoginButton = findViewById(R.id.wechat_login_button_id);
        accountEditText = findViewById(R.id.account_login);
        codeEditText = findViewById(R.id.password_yanzheng_login);

        wechatLoginButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (!checkBox.isChecked()) {
                    Toast.makeText(Login.this, "请您勾选协议", Toast.LENGTH_SHORT).show();
                } else {
                    String account = accountEditText.getText().toString().trim();
                    String code = codeEditText.getText().toString().trim();

                    if (account.isEmpty() || code.isEmpty()) {
                        Toast.makeText(Login.this, "账号和验证码不能为空", Toast.LENGTH_SHORT).show();
                    } else {
                        Toast.makeText(Login.this, "登录成功！", Toast.LENGTH_SHORT).show();
                        Intent intent = new Intent(Login.this, MainActivity.class);
                        intent.putExtra("isLoggedIn", true); // 传递登录成功标志位
                        startActivity(intent);
                        finish();
                    }
                }
            }
        });
    }

    public void goToRegister(View view) {
        Intent intent = new Intent(Login.this, Register.class);
        startActivity(intent);
    }
}